/*     */ package com.xhgk.action;
/*     */ 
/*     */ import com.xhgk.domain.ConstantParam;
/*     */ import com.xhgk.domain.Info;
/*     */ import com.xhgk.domain.Paging;
/*     */ import com.xhgk.domain.Periodical;
/*     */ import com.xhgk.service.PeriodicalService;
/*     */ import com.xhgk.service.impl.PeriodicalServiceImpl;
/*     */ import com.xhgk.utis.JsonMyUtil;
/*     */ import com.xhgk.utis.StringUtils;
/*     */ import java.awt.Desktop;
/*     */ import java.io.File;
/*     */ import java.io.IOException;
/*     */ import java.net.InetAddress;
/*     */ import java.net.URLEncoder;
/*     */ import java.net.UnknownHostException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.TreeSet;
/*     */ import javax.servlet.ServletConfig;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.ServletRequest;
/*     */ import javax.servlet.ServletResponse;
/*     */ import javax.servlet.http.HttpServlet;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PeriodicalAction
/*     */   extends HttpServlet
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*  40 */   private String hostAddress = null;
/*  41 */   private String defaultLibrary = null;
/*  42 */   public PeriodicalService bookService = (PeriodicalService)new PeriodicalServiceImpl();
/*  43 */   public static HashMap<String, List<Integer>> library_map = new HashMap<String, List<Integer>>();
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void init(ServletConfig config) throws ServletException {
/*  51 */     super.init(config);
/*  52 */     if (StringUtils.isEmpty(config.getInitParameter("hostAddress"))) {
/*     */       
/*     */       try {
/*  55 */         this.hostAddress = InetAddress.getLocalHost().getHostAddress();
/*  56 */       } catch (UnknownHostException e) {
/*  57 */         this.hostAddress = "127.0.0.1";
/*  58 */         e.printStackTrace();
/*     */       } 
/*     */     }
/*  61 */     String initParameter = config.getInitParameter("library");
/*  62 */     String[] array = initParameter.split("\\+"); byte b; int i; String[] arrayOfString1;
/*  63 */     for (i = (arrayOfString1 = array).length, b = 0; b < i; ) { String librarys = arrayOfString1[b];
/*     */       
/*  65 */       String[] library = librarys.split("=");
/*  66 */       List<Integer> treeSet = new ArrayList<Integer>(library.length); byte b1; int j; String[] arrayOfString2;
/*  67 */       for (j = (arrayOfString2 = library[1].split(",")).length, b1 = 0; b1 < j; ) { String year = arrayOfString2[b1];
/*     */         
/*  69 */         treeSet.add(Integer.valueOf(Integer.parseInt(year))); b1++; }
/*     */       
/*  71 */       library_map.put(library[0], treeSet); b++; }
/*     */     
/*  73 */     ConstantParam.LUCENE_FIELE = config.getInitParameter("field").split(",");
/*  74 */     config.getServletContext().setAttribute("LUCENE_FIELE", ConstantParam.LUCENE_FIELE);
/*     */     
/*  76 */     if (StringUtils.isNotEmpty(config.getInitParameter("indexDirectory"))) {
/*     */       
/*  78 */       ConstantParam.indexDirectory = config.getInitParameter("indexDirectory");
/*     */     }
/*     */     else {
/*     */       
/*  82 */       ConstantParam.indexDirectory = System.getProperty("user.dir").concat("library/tomcat/webapps/researchFile/index");
/*     */     } 
/*  84 */     if (StringUtils.isNotEmpty(config.getInitParameter("shujuDirectory"))) {
/*     */       
/*  86 */       ConstantParam.shujuDirectory = config.getInitParameter("shujuDirectory");
/*     */     }
/*     */     else {
/*     */       
/*  90 */       ConstantParam.shujuDirectory = System.getProperty("user.dir").concat("library/tomcat/webapps/researchFile/");
/*     */     } 
/*  92 */     this.defaultLibrary = config.getInitParameter("defaultLibrary");
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/*  98 */     doPost(req, resp);
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/* 104 */     req.setCharacterEncoding("UTF-8");
/* 105 */     resp.setCharacterEncoding("UTF-8");
/* 106 */     resp.setContentType("text/html;charset=".concat(resp.getCharacterEncoding()));
/* 107 */     if (this.hostAddress == null || this.hostAddress.equals(req.getRemoteAddr()) || "127.0.0.1".equals(req.getRemoteAddr()) || "localhost".equals(req.getRemoteAddr())) {
/*     */       
/* 109 */       String method = req.getParameter("method");
/* 110 */       if (StringUtils.isEmpty(method))
/* 111 */         method = "index"; 
/* 112 */       String result = null;
/*     */       try {
/* 114 */         if (method.equals("index")) {
/*     */           
/* 116 */           result = index(req);
/*     */         }
/* 118 */         else if (method.equals("periodical")) {
/*     */           
/* 120 */           result = periodical(req, resp);
/*     */         }
/* 122 */         else if (method.equals("catalogue")) {
/*     */           
/* 124 */           result = catalogue(req);
/*     */         }
/* 126 */         else if (method.equals("pdfView")) {
/*     */           
/* 128 */           result = pdfView(req);
/*     */         }
/* 130 */         else if (method.equals("info")) {
/*     */           
/* 132 */           result = info(req);
/*     */         }
/* 134 */         else if (method.equals("search")) {
/*     */           
/* 136 */           result = search(req, resp);
/*     */         }
/* 138 */         else if (method.equals("paging")) {
/*     */           
/* 140 */           result = paging(req);
/*     */         }
/* 142 */         else if (method.equals("html")) {
/*     */           
/* 144 */           result = html(req);
/*     */         }
/* 146 */         else if (method.equals("toAdvancedSearch")) {
/*     */           
/* 148 */           result = toAdvancedSearch(req);
/*     */         }
/* 150 */         else if (method.equals("advancedSearch")) {
/*     */           
/* 152 */           result = seniorSearch(req, resp);
/*     */         } 
/* 154 */       } catch (Exception ex) {
/* 155 */         ex.printStackTrace();
/*     */       } finally {
/* 157 */         if (result != null) {
/* 158 */           req.getRequestDispatcher("/WEB-INF/jsps/".concat(result).concat(".jsp")).forward((ServletRequest)req, (ServletResponse)resp);
/*     */         }
/*     */       } 
/*     */     } 
/*     */   }
/*     */   
/*     */   private String seniorSearch(HttpServletRequest request, HttpServletResponse response) {
/* 165 */     Map<String, String[]> parameterMap = request.getParameterMap();
/* 166 */     Map<String, String> searchMap = new HashMap<String, String>(parameterMap.size());
/* 167 */     for (Map.Entry<String, String[]> entrySet : parameterMap.entrySet()) {
/* 168 */       searchMap.put(entrySet.getKey(), ((String[])entrySet.getValue())[0]);
/*     */     }
/*     */     
/* 171 */     String order = searchMap.get("order");
/* 172 */     searchMap.remove("order");
/* 173 */     searchMap.remove("method");
/* 174 */     String query = this.bookService.seniorSearch(searchMap);
/* 175 */     StringBuffer buffer = new StringBuffer();
/*     */     try {
/* 177 */       buffer.append("index.do?method=paging");
/* 178 */       buffer.append("&query=").append(URLEncoder.encode(query, "UTF-8"));
/* 179 */       buffer.append("&order=").append(order.toString());
/* 180 */       response.sendRedirect(buffer.toString());
/* 181 */     } catch (IOException e) {
/* 182 */       e.printStackTrace();
/*     */     } 
/* 184 */     return null;
/*     */   }
/*     */ 
/*     */   
/*     */   private String toAdvancedSearch(HttpServletRequest req) {
/* 189 */     return "advancedSearch";
/*     */   }
/*     */   
/*     */   private String periodical(HttpServletRequest req, HttpServletResponse resp) throws IOException {
/* 193 */     resp.setContentType("text/json;carhset=utf-8");
/* 194 */     String library = req.getParameter("library");
/* 195 */     String year = req.getParameter("year");
/* 196 */     Periodical periodical = new Periodical();
/* 197 */     periodical.setLibrary(library);
/* 198 */     periodical.setYear(Integer.valueOf(Integer.parseInt(year)));
/* 199 */     TreeSet<Periodical> periodicals = this.bookService.getPeriodicals(periodical);
/* 200 */     resp.setContentType("text/json;charset=utf-8");
/* 201 */     resp.setCharacterEncoding("UTF-8");
/* 202 */     String set2json = JsonMyUtil.set2json(periodicals);
/* 203 */     resp.getWriter().println(set2json);
/* 204 */     resp.flushBuffer();
/* 205 */     return null;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private String html(HttpServletRequest req) {
/* 219 */     return req.getParameter("name");
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public String index(HttpServletRequest request) throws IOException {
/* 235 */     String library = request.getParameter("library");
/* 236 */     if (StringUtils.isEmpty(library)) {
/* 237 */       library = this.defaultLibrary;
/* 238 */     } else if (library.startsWith("国外党史动")) {
/* 239 */       library = "国外党史动态";
/* 240 */     }  String year = request.getParameter("year");
/* 241 */     if (library_map.containsKey(library)) {
/*     */       
/* 243 */       List<Integer> years = library_map.get(library);
/* 244 */       if (years.size() > 0) {
/*     */         
/* 246 */         Periodical periodical = new Periodical();
/* 247 */         periodical.setLibrary(library);
/* 248 */         if (StringUtils.isEmpty(year)) {
/* 249 */           periodical.setYear(years.get(0));
/*     */         } else {
/* 251 */           periodical.setYear(Integer.valueOf(Integer.parseInt(year)));
/* 252 */         }  request.setAttribute("periodical", periodical);
/* 253 */         request.setAttribute("years", years);
/*     */       } 
/*     */     } 
/* 256 */     return "index";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public String catalogue(HttpServletRequest request) throws IOException {
/* 273 */     Periodical periodical = this.bookService.getCatalogue(Integer.valueOf(Integer.parseInt(request.getParameter("id"))));
/* 274 */     request.setAttribute("periodical", periodical);
/* 275 */     request.setAttribute("years", library_map.get(periodical.getLibrary()));
/* 276 */     return "catalogue";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public String pdfView(HttpServletRequest request) throws IOException {
/* 291 */     File file = new File(String.format("%s/%s", new Object[] { ConstantParam.shujuDirectory, request.getParameter("pdf") }));
/* 292 */     if (file.exists()) {
/*     */       
/*     */       try {
/* 295 */         Desktop.getDesktop().open(file);
/* 296 */       } catch (Exception ex) {
/*     */         
/* 298 */         request.setAttribute("message", "打开PDF失败，请检查是否安装PDF阅读软件！");
/*     */       } 
/*     */     } else {
/*     */       
/* 302 */       request.setAttribute("message", "文件不存在！");
/*     */     } 
/* 304 */     return "view";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public String info(HttpServletRequest request) throws IOException {
/* 321 */     Periodical periodical = this.bookService.getInfo(Integer.valueOf(Integer.parseInt(request.getParameter("id"))));
/*     */ 
/*     */     
/* 324 */     String content = periodical.getInfo().getContent();
/* 325 */     content = content.replaceAll(",", "，");
/* 326 */     periodical.getInfo().setContent(content);
/*     */ 
/*     */     
/* 329 */     request.setAttribute("periodical", periodical);
/* 330 */     request.setAttribute("years", library_map.get(periodical.getLibrary()));
/* 331 */     return "info";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public String search(HttpServletRequest request, HttpServletResponse response) {
/* 348 */     Periodical periodical = new Periodical();
/* 349 */     periodical.setQuery(request.getParameter("query"));
/* 350 */     periodical.setSearch_field(request.getParameter("search_field"));
/* 351 */     periodical.setKeyword(request.getParameter("keyword"));
/* 352 */     periodical.setSearch_library(request.getParameter("search_library"));
/* 353 */     this.bookService.search(periodical);
/* 354 */     StringBuffer buffer = new StringBuffer();
/*     */     try {
/* 356 */       buffer.append("index.do?method=paging");
/* 357 */       if (StringUtils.isNotEmpty(periodical.getKeyword()))
/* 358 */         buffer.append("&keyword=").append(URLEncoder.encode(periodical.getKeyword(), "UTF-8")); 
/* 359 */       if (StringUtils.isNotEmpty(periodical.getSearch_library()))
/* 360 */         buffer.append("&search_library=").append(URLEncoder.encode(periodical.getSearch_library(), "UTF-8")); 
/* 361 */       if (StringUtils.isNotEmpty(periodical.getQuery()))
/* 362 */         buffer.append("&query=").append(URLEncoder.encode(periodical.getQuery(), "UTF-8")); 
/* 363 */       response.sendRedirect(buffer.toString());
/* 364 */     } catch (IOException e) {
/* 365 */       e.printStackTrace();
/*     */     } 
/* 367 */     return null;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public String paging(HttpServletRequest request) throws Exception {
/* 385 */     Paging<Info> paging = new Paging();
/* 386 */     Periodical periodical = new Periodical();
/* 387 */     periodical.setKeyword(request.getParameter("keyword"));
/* 388 */     periodical.setQuery(request.getParameter("query"));
/* 389 */     periodical.setSearch_library(request.getParameter("search_library"));
/* 390 */     String order = request.getParameter("order");
/* 391 */     if (StringUtils.isNotEmpty(order))
/*     */     {
/* 393 */       periodical.setOrder(Boolean.parseBoolean(order));
/*     */     }
/* 395 */     if (StringUtils.isNotEmpty(request.getParameter("currPageNo")))
/* 396 */       paging.setCurrPageNo(Integer.parseInt(request.getParameter("currPageNo"))); 
/* 397 */     this.bookService.pagper(paging, periodical);
/* 398 */     request.setAttribute("periodical", periodical);
/* 399 */     request.setAttribute("paging", paging);
/* 400 */     request.setAttribute("years", library_map.get(periodical.getLibrary()));
/* 401 */     return "result";
/*     */   }
/*     */ }


/* Location:              D:\library\tomcat\webapps\ROOT\WEB-INF\classes\!\com\xhgk\action\PeriodicalAction.class
 * Java compiler version: 5 (49.0)
 * JD-Core Version:       1.1.3
 */